package com.ea.eadp.nexus.test.common;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ChuanYe on 7/25/2014.
 */
public enum NexusGatewayApiEnum {
    pid_me_get("user", "GET", "/identity/pids/me", Scope.BASIC_IDENTITY),
    pid_get("user", "GET", "/identity/pids/${pid}", Scope.BASIC_IDENTITY),
    pid_multisearch_get("multiuser", "GET", "/identity/pids/multisearch?ids=${pidlist}", Scope.IDENTITY_MULTI_SEARCH),
    pid_profile_post("user_profile", "POST", "/identity/pids/${pid}/profileinfo", Scope.BASIC_IDENTITY_WRITE),
    pid_profile_put("user_profile", "PUT", "/identity/pids/${pid}/profileinfo/category/${category}/entryid/${entryid}", Scope.BASIC_IDENTITY_WRITE),
    pid_profile_delete("user_profile", "DELETE", "/identity/pids/${pid}/profileinfo/category/${category}/entryid/${entryid}", Scope.BASIC_IDENTITY_WRITE),
    pid_profile_get("user_profile", "GET", "/identity/pids/${pid}/profileinfo/category/${category}/entryid/${entryid}", Scope.BASIC_IDENTITY),
    pid_profile_search("user_profile", "GET", "/identity/pids/${pid}/profileinfo", Scope.BASIC_IDENTITY),

    pid_address_post("user_address", "POST", "/identity/pids/${pid}/addresses", Scope.BASIC_IDENTITY_WRITE),
    pid_address_delete("user_address", "DELETE", "/identity/addresses/${address}", Scope.BASIC_IDENTITY_WRITE),
    pid_address_get("user_address", "GET", "/identity/addresses/${address}", Scope.BASIC_IDENTITY),
    pid_address_search("user_address", "GET", "/identity/pids/${pid}/addresses", Scope.BASIC_IDENTITY),

    pid_optin_post("user_optin", "POST", "/identity/pids/${pid}/optins/${optin}", Scope.BASIC_IDENTITY_WRITE),
    pid_optin_delete("user_optin", "DELETE", "/identity/pids/${pid}/optins/${optin}", Scope.BASIC_IDENTITY_WRITE),
    pid_optin_get("user_optin", "GET", "/identity/pids/${pid}/optins/${optin}", Scope.BASIC_IDENTITY),
    pid_optin_search("user_optin", "GET", "/identity/pids/${pid}/optins", Scope.BASIC_IDENTITY),
    pid_second_chance_optin_get("user_optin", "GET", "/identity/pids/${pid}/secondchanceoptin", Scope.BASIC_SCOI),

    pid_tos_post("user_tos", "POST", "/identity/pids/${pid}/tos", Scope.BASIC_IDENTITY_WRITE),
    pid_tos_delete("user_tos", "DELETE", "/identity/tos/${tos}", Scope.BASIC_IDENTITY_WRITE),
    pid_tos_get("user_tos", "GET", "/identity/tos/${tos}", Scope.BASIC_IDENTITY),
    pid_tos_search("user_tos", "GET", "/identity/pids/${pid}/tos", Scope.BASIC_IDENTITY),

    pid_device_profile_post("user_device_profile", "POST", "/identity/pids/${pid}/deviceprofile", Scope.BASIC_IDENTITY_WRITE),
    pid_device_profile_delete("user_device_profile", "DELETE", "/identity/pids/${pid}/deviceprofile/${device}", Scope.BASIC_IDENTITY_WRITE),
    pid_device_profile_get("user_device_profile", "GET", "/identity/pids/${pid}/deviceprofile/${device}", Scope.BASIC_IDENTITY),
    pid_device_profile_search("user_device_profile", "GET", "/identity/pids/${pid}/deviceprofile", Scope.BASIC_IDENTITY),

    pid_privacy_setting_post("user_privacy_setting", "POST", "/identity/pids/${pid}/privacysettings", Scope.BASIC_IDENTITY_WRITE),
    pid_privacy_setting_put("user_privacy_setting", "PUT", "/identity/pids/${pid}/privacysettings", Scope.BASIC_IDENTITY_WRITE),
    pid_privacy_setting_get("user_privacy_setting", "GET", "/identity/pids/${pid}/privacysettings", Scope.BASIC_IDENTITY),

    pid_relationship_post("user_relationship", "POST", "/identity/pids/${pid}/relationships", Scope.BASIC_IDENTITY_WRITE),
    pid_relationship_delete("user_relationship", "DELETE", "/identity/relationships/${relationship}", Scope.BASIC_IDENTITY_WRITE),
    pid_relationship_get("user_relationship", "GET", "/identity/relationships/${relationship}", Scope.BASIC_IDENTITY),
    pid_relationship_search("user_relationship", "GET", "/identity/relationships?relatedPidId=${pid}", Scope.BASIC_IDENTITY),
    pid_relationship_search_by_pid("user_relationship", "GET", "/identity/pids/${pid}/relationships", Scope.BASIC_IDENTITY),

    pid_status_put("user_status", "PUT", "/identity/pids/${pid}", Scope.BASIC_IDENTITY_WRITE),

    persona_post("persona", "POST", "/identity/pids/${pid}/personas", Scope.BASIC_PERSONA_WRITE),
    persona_put("persona", "PUT", "/identity/pids/${pid}/personas/${persona}", Scope.BASIC_PERSONA_WRITE),
    persona_delete("persona", "DELETE", "/identity/pids/${pid}/personas/${persona}", Scope.BASIC_PERSONA_WRITE),
    persona_get("persona", "GET", "/identity/personas/${persona}", Scope.BASIC_PERSONA),
    persona_get_by_pid("persona", "GET", "/identity/pids/${pid}/personas/${persona}", Scope.BASIC_PERSONA),
    persona_search_by_pid("persona", "GET", "/identity/pids/${pid}/personas", Scope.BASIC_PERSONA),
    persona_search_by_pid_and_namespace("persona", "GET", "/identity/pids/${pid}/personas?namespaceName=${namespace}", Scope.BASIC_PERSONA),
    persona_psnaccesstoken_get_by_personaid("persona", "GET", "/identity/personas/${personaId}/psnaccesstoken", Scope.BASIC_PSNTOKEN),
    persona_permissioninfo_get_by_personaid("persona", "GET", "/identity/personas/${personaId}/permissioninfo", Scope.BASIC_PRIVILEGE),
    persona_multisearch_get("persona", "POST", "/identity/links/extref/bulk", Scope.BASIC_ANTELOPE_LINKS_BULK),

    entitlement_post("entitlement", "POST", "/identity/pids/${pid}/entitlements", Scope.BASIC_ENTITLEMENT_WRITE),
    entitlement_searchorcreate("entitlement", "POST", "/identity/pids/${pid}/entitlements/searchorcreate", Scope.BASIC_ENTITLEMENT_WRITE),
    entitlement_put("entitlement", "PUT", "/identity/pids/${pid}/entitlements/${entitlement}", Scope.BASIC_ENTITLEMENT_WRITE),
    entitlement_auth_persona_post("entitlement", "POST", "/identity/entitlements/${entitlement}/personas/${persona}", Scope.BASIC_ENTITLEMENT_WRITE),
    entitlement_auth_persona_delete("entitlement", "DELETE", "/identity/entitlements/${entitlement}/personas/${persona}", Scope.BASIC_ENTITLEMENT_WRITE),
    entitlement_get("entitlement", "GET", "/identity/entitlements/${entitlement}", Scope.BASIC_ENTITLEMENT),
    entitlement_get_by_pid("entitlement", "GET", "/identity/pids/${pid}/entitlements/${entitlement}", Scope.BASIC_ENTITLEMENT),
    entitlement_search("entitlement", "GET", "/identity/pids/${pid}/entitlements", Scope.BASIC_ENTITLEMENT),
    entitlement_search_active("entitlement", "GET", "/identity/pids/${pid}/entitlements?status=ACTIVE", Scope.BASIC_ENTITLEMENT),
    entitlement_search_by_persona("entitlement", "GET", "/identity/personas/${persona}/entitlements", Scope.BASIC_ENTITLEMENT),
    entitlement_search_by_persona_active("entitlement", "GET", "/identity/personas/${persona}/entitlements?status=ACTIVE", Scope.BASIC_ENTITLEMENT),

    post_encrypted_token("token", "POST", "/identity/encryptedtoken?expiration=${expiration}&signature=${signature}&foo=bar", Scope.BASIC_ENCRYPTED_TOKEN),
    get_encrypted_token("token", "GET", "/identity/encryptedtoken?signature=${signature}&token=${token}", Scope.BASIC_ENCRYPTED_TOKEN),

    get_security_state("admin_security_state", "GET", "/identity/pids/${pid}/securitystate", Scope.BASIC_ADMIN),
    delete_security_state("admin_security_state", "DELETE", "/identity/pids/${pid}/securitystate", Scope.BASIC_ADMIN),

    post_entxfer("admin_ent_xfer", "POST", "/identity/entitlementxfers", Scope.BASIC_ADMIN),
    get_entxfer("admin_ent_xfer", "GET", "/identity/entitlementxfers/${entitlementxfer}", Scope.BASIC_ADMIN),
    search_entxfers_by_user("admin_ent_xfer", "GET", "/identity/pids/${pid}/entitlementxfers", Scope.BASIC_ADMIN),
    search_entxfers_by_ent("admin_ent_xfer", "GET", "/identity/entitlements/${entitlement}/entitlementxfers", Scope.BASIC_ADMIN),

    suggest_persona     ("utility", "GET", "/identity/personas/suggestions?baseName=foobar&namespaceName=XBOX", Scope.BASIC_UTILITY),
    preview_persona_name("utility", "GET", "/identity/personanamepreviews?displayName=TotallyValid123&namespaceName=cem_ea_id", Scope.BASIC_UTILITY),
    get_filtered_string ("utility", "GET", "/identity/profanity/filteredstring?inputString=test", Scope.BASIC_UTILITY),
    check_email         ("utility", "GET", "/identity/pids/emailaddresscheck?email=${email}", Scope.BASIC_UTILITY),
    get_ipgeolocation   ("utility", "GET", "/identity/ipgeolocations/${ipgeolocation}", Scope.BASIC_UTILITY),

    search_group("domain_data", "GET", "/identity/groups", Scope.BASIC_DOMAINDATA),
    get_group("domain_data", "GET", "/identity/groups/${group}", Scope.BASIC_DOMAINDATA),
    get_all_namespaces("domain_data", "GET", "/identity/namespaces", Scope.BASIC_DOMAINDATA),
    get_namespace("domain_data", "GET", "/identity/namespaces/${namespace}", Scope.BASIC_DOMAINDATA),
    get_all_namespace_properties("domain_data", "GET", "/identity/namespaces/${namespace}/properties", Scope.BASIC_DOMAINDATA),
    get_namespace_property("domain_data", "GET", "/identity/namespaces/${namespace}/properties/${property}", Scope.BASIC_DOMAINDATA),
    get_age_requirement         ("domain_data", "GET", "/identity/agerequirements/US", Scope.BASIC_DOMAINDATA),
    get_info_sharing_requirement("domain_data", "GET", "/identity/infosharingrequirements/US", Scope.BASIC_DOMAINDATA),
    search_countries            ("domain_data", "GET", "/identity/countries", Scope.BASIC_DOMAINDATA),
    get_all_sources             ("domain_data", "GET", "/identity/sources", Scope.BASIC_DOMAINDATA),
    get_all_requestors          ("domain_data", "GET", "/identity/requestors", Scope.BASIC_DOMAINDATA),
    get_all_projects            ("domain_data", "GET", "/identity/projects", Scope.BASIC_DOMAINDATA),
    get_user_status             ("domain_data", "GET", "/identity/pids/statuses", Scope.BASIC_DOMAINDATA),
    get_user_reason_code        ("domain_data", "GET", "/identity/pids/reasoncodes", Scope.BASIC_DOMAINDATA),
    get_user_extref_type        ("domain_data", "GET", "/identity/pids/externalreftypes", Scope.BASIC_DOMAINDATA),
    get_profile_info_category   ("domain_data", "GET", "/identity/pids/profileinfo/profileinfocategories", Scope.BASIC_DOMAINDATA),
    get_profile_info_type       ("domain_data", "GET", "/identity/pids/profileinfo/profileinfotypes", Scope.BASIC_DOMAINDATA),
    get_persona_extref_type     ("domain_data", "GET", "/identity/personas/externalreftypes", Scope.BASIC_DOMAINDATA),
    get_persona_status          ("domain_data", "GET", "/identity/personas/statuses", Scope.BASIC_DOMAINDATA),
    get_persona_reason_code     ("domain_data", "GET", "/identity/personas/statusreasoncodes", Scope.BASIC_DOMAINDATA),
    get_entitlement_status      ("domain_data", "GET", "/identity/entitlements/statuses", Scope.BASIC_DOMAINDATA),
    get_entitlement_reason_code ("domain_data", "GET", "/identity/entitlements/statusreasoncodes", Scope.BASIC_DOMAINDATA),
    get_password_rules          ("domain_data", "GET", "/identity/pids/passwordrules", Scope.BASIC_DOMAINDATA),

    post_checkout("commerce","POST", "/commerce/pids/${pid}/checkout", Scope.BASIC_COMMERCE_WRITE),
    put_code("commerce","PUT", "/commerce/codes/${code}?pidId=${pid}", Scope.BASIC_COMMERCE_WRITE),

    get_cart("cart","GET", "/commerce/carts/${cart}/pids/${pid}?countryCode=US", Scope.BASIC_COMMERCE, "xml"),
    post_close_cart("cart","POST", "/commerce/carts/${cart}/pids/${pid}?action=close", Scope.BASIC_COMMERCE_WRITE, "xml"),
    delete_offer("cart","DELETE", "/commerce/carts/${cart}/pids/${pid}/offerEntries/${offer}?countryCode=US", Scope.BASIC_COMMERCE_WRITE, "xml"),
    post_add_offer("cart","POST", "/commerce/carts/${cart}/pids/${pid}/offerEntries?countryCode=US&storeId=CART-STR-001&needFullCartInfo=true", Scope.BASIC_COMMERCE_WRITE, "xml"),

    post_billing_account("billing", "POST", "/billing/pids/${pid}/billingaccounts", Scope.BASIC_BILLING_WRITE, "xml"),
    get_wallet_account("billing", "GET", "/billing/pids/${pid}/walletaccounts", Scope.BASIC_BILLING, "xml"),
    post_wallet_credits("billing", "POST", "/billing/billingaccounts/${account}/walletcredits", Scope.BASIC_BILLING_WRITE, "xml"),
    post_vctransfers("billing", "POST", "/billing/vctransfers", Scope.BASIC_BILLING_WRITE, "xml"),

    search_user_bulk("user", "GET", "/identity/originAccount/bulk?userId=${pid}&userId=${pid2}", Scope.BULK_IDENTITY),
    get_user_searchable("user", "GET", "/identity/pids/${pid}/searchable", Scope.BULK_IDENTITY),

    get_xbltoken("xbltoken", "GET", "/identity/personas/${persona}/xbltoken", Scope.BASIC_XBLTOKEN),

    get_twofactor("twofactor", "GET", "/identity/pids/${pid}/twofactor", Scope.BASIC_TWOFACTOR),

    search_client_migration_record("clientmigrationrecord", "GET", "/identity/clientmigrationrecord", Scope.BASIC_MIGRATION_RECORD),

    get_risk_reftable_items("risk", "GET", "/risk/reftable/items?tableName=${tableName}&key=${key}", Scope.BASIC_RESON, "xml"),
    get_risk_reftable_items_in_page("risk", "GET", "/risk/reftable/items?tableName=${tableName}&minItemId=${minItemId}", Scope.BASIC_RESON, "xml"),
    create_risk_reftable_items("risk", "POST", "/risk/reftable/items", Scope.BASIC_RESON, "xml"),
    delete_risk_reftable_items("risk", "POST", "/risk/reftable/items/del", Scope.BASIC_RESON, "xml"),

    console_get("securemtx", "GET", "/commerce/console?platform=${platform}&entitlementLabel=${entitlementLabel}", Scope.BASIC_COMMERCE_CONSOLE, "xml"),
    console_begin_consume_post("securemtx", "POST", "/commerce/console/beginconsume", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    console_consume_post("securemtx", "POST", "/commerce/console/consume/${transactionId}", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    console_exfulfillcomplete_put("securemtx", "PUT", "/commerce/console/fulfillcomplete/${transactionId}", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    console_put("securemtx", "POST", "/commerce/console/cancel", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),

    securemtx_get("securemtx", "GET", "/commerce/securemtx", Scope.BASIC_COMMERCE_CONSOLE, "xml"),
    securemtx_post("securemtx", "POST", "/commerce/securemtx", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    securemtx_action_post("securemtx", "POST", "/commerce/securemtx/${transactionId}", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    securemtx_delete("securemtx", "POST", "/commerce/securemtx/${transactionId}/?", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),
    securemtx_balance_get("securemtx", "GET", "/commerce/securemtx/balance", Scope.BASIC_COMMERCE_CONSOLE, "xml"),
    securemtx_balance_post("securemtx", "POST", "/commerce/securemtx/balance", Scope.BASIC_COMMERCE_CONSOLE, "xml"),
    securemtx_durable_post("securemtx", "POST", "/commerce/securemtx/durable", Scope.BASIC_COMMERCE_CONSOLE_WRITE, "xml"),

    get_user_login_history("tracking", "GET", "/logquery/login?pid=${pid}", Scope.CUSTOMIZEDLOG_READ, "json"),
    get_user_account_change_history("tracking", "GET", "/logquery/account_change?pid=${pid}", Scope.CUSTOMIZEDLOG_READ, "json");

    private String category;
    private String method;
    private String url;
    private Scope scope;
    private String format = "json";

    private NexusGatewayApiEnum(String category, String method, String url, Scope scope){
        this.category = category;
        this.method = method;
        this.url = url;
        this.scope = scope;
    }

    private NexusGatewayApiEnum(String category, String method, String url, Scope scope, String format){
        this.category = category;
        this.method = method;
        this.url = url;
        this.scope = scope;
        this.format = format;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String function) {
        this.category = function;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Scope getScope() {
        return scope;
    }

    public void setScope(Scope scope) {
        this.scope = scope;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public static List<NexusGatewayApiEnum> getApisByScope(Scope scope) {
        List<NexusGatewayApiEnum> apis = new ArrayList<NexusGatewayApiEnum>();
        for (NexusGatewayApiEnum a : NexusGatewayApiEnum.values()) {
            if (a.getScope() == scope) {
                apis.add(a);
            }
        }
        return apis;
    }

    public static List<NexusGatewayApiEnum> getApisByMethod(String method) {
        List<NexusGatewayApiEnum> apis = new ArrayList<NexusGatewayApiEnum>();
        for (NexusGatewayApiEnum a : NexusGatewayApiEnum.values()) {
            if (a.getMethod() == method) {
                apis.add(a);
            }
        }
        return apis;
    }

}
